Sort column in listview

I have another problem.

I am trying to associate a sort callback with a column in a listview using

set(delItmsLST, DEL_OBJS_NUM, doSortInt)


and

 

setSortColumn(delItmsLST, DEL_OBJS_NUM)


but when I click the column it is always the first column (index 0) that is being sorted.

Any ideas?
Karl

 


kabr - Thu Jul 28 08:30:40 EDT 2011

Re: Sort column in listview
llandale - Thu Jul 28 18:07:49 EDT 2011

You allow the user to sort a column when she clicks on it by defining the ListView and the column correctly and have to assign the "callback" to a precise piece of code. There is no "callback' in the "set" or "button" or "apply" sense.

The required precise code looks like this:

//*******************
int    fDbeLv_clbkSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end fDbeLv_clbkSortFunction()


I advise you to make the function look exactly like that, but you can rename it and remove the comments. If you tweak the code, even with no functional change, it can crash the function. Its inexplicable, but some tweaks might work and some don't and I have no clue why. Leave it as is.

The ListView must be declared with integer option "listViewOptionSortText".

To allow sorting of a column do this:
set(dbeListView, ColNum, fDbeLv_clbkSortFunction)

So now that column can be sorted. There are two ways:
(1) The user clicks on the column title.
(2) DXL issues: setSortColumn(dbeLV, ColNum)

You may sometimes need to know which one is sorted:
int SortCol = getSortColumn(dbeLV)

Yes, you must keep track of which column is which and contains what data. That's easier if you figure out your columns and insert them from left to right, insert column 0, then 1, then 2.

 

 

  • Louie

 

 

Re: Sort column in listview
kabr - Fri Jul 29 06:02:47 EDT 2011

llandale - Thu Jul 28 18:07:49 EDT 2011

You allow the user to sort a column when she clicks on it by defining the ListView and the column correctly and have to assign the "callback" to a precise piece of code. There is no "callback' in the "set" or "button" or "apply" sense.

The required precise code looks like this:

//*******************
int    fDbeLv_clbkSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end fDbeLv_clbkSortFunction()


I advise you to make the function look exactly like that, but you can rename it and remove the comments. If you tweak the code, even with no functional change, it can crash the function. Its inexplicable, but some tweaks might work and some don't and I have no clue why. Leave it as is.

The ListView must be declared with integer option "listViewOptionSortText".

To allow sorting of a column do this:
set(dbeListView, ColNum, fDbeLv_clbkSortFunction)

So now that column can be sorted. There are two ways:
(1) The user clicks on the column title.
(2) DXL issues: setSortColumn(dbeLV, ColNum)

You may sometimes need to know which one is sorted:
int SortCol = getSortColumn(dbeLV)

Yes, you must keep track of which column is which and contains what data. That's easier if you figure out your columns and insert them from left to right, insert column 0, then 1, then 2.

 

 

  • Louie

 

 

Thanks for your response, Louie!

Of course I have the needed callback functions and with the exact code, I only did not quote them.
and, yes, I insert the columns from left to right and fill them with data from left to right.

What I forgot was the "listViewOptionSortText".
Now when I click on a column title the associated callback fires.
But it still does not work.

with

print "s1: " s1 "\ts2: " s2 "\n"


at the top of the callbacks I find, that only the first row in the listview is being evaluated.

What am I doing wrong?

Karl

Re: Sort column in listview
kabr - Fri Jul 29 09:05:17 EDT 2011

kabr - Fri Jul 29 06:02:47 EDT 2011

Thanks for your response, Louie!

Of course I have the needed callback functions and with the exact code, I only did not quote them.
and, yes, I insert the columns from left to right and fill them with data from left to right.

What I forgot was the "listViewOptionSortText".
Now when I click on a column title the associated callback fires.
But it still does not work.

with

print "s1: " s1 "\ts2: " s2 "\n"


at the top of the callbacks I find, that only the first row in the listview is being evaluated.

What am I doing wrong?

Karl

solved it.
reason was not having incremented the row index correctly.